/**
 * 
 */
package com.google.code.maven.plugin.http.client.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import com.google.code.maven.plugin.http.client.Credentials;

/**
 * <h1>Credentials configuration</h1> maven configuration pojo for defining credentials setting.
 * 
 * @author Nadim Benabdenbi
 * @version 1.0
 * @since JDK1.6
 */
public class CredentialsConfiguration extends Credentials  {
	
	protected static final AtomicInteger id = new AtomicInteger();
	
	public Credentials build(DefaultListableBeanFactory factory) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Credentials.class);
		String beanId = Credentials.class.getSimpleName() + id.incrementAndGet();
		builder.addPropertyValue("login", getLogin() );
		builder.addPropertyValue("password", getPassword() );
		factory.registerBeanDefinition(beanId, builder.getBeanDefinition());
		return factory.getBean(beanId, Credentials.class);
	}

}
